package com.oracle.stringreview;

/**
 * @author zhouyanxiang
 * @create 2020-08-2020/8/12-22:26
 */
public class StringTest {

    public static void main(String[] args) {
        String str = "Hello World";
        // length()方法空格也要算上
        int length = str.length();
        System.out.println("the str length is " + length);

        // charAt(i)中的下标i是从0-str.length()-1
        char chStr = str.charAt(0);
        char chStr2 = str.charAt(10);
        System.out.println(chStr);
        System.out.println(chStr2);


        // toCharArray()方法转化为一个字符数组
        for (char ch : str.toCharArray()){
            System.out.println(ch);
        }

        //stringTest.indexOf(String str)返回的是str在字符串stringTest中的位置，如果存在就返回下标索引，如果不存在就返回-1
        String strTest = "你好，世界";
        int s1 = strTest.indexOf("H");
        int s2 = strTest.indexOf("你");
        System.out.println(s1);
        System.out.println(s2);

        String stringUpperer = "Hello World";
        // 字母的部分全部转换成大写，非字母的部分不变
        String toUpperCase = stringUpperer.toUpperCase();
        // 字母的而部分全部转换成小写，非字母的部分不变
        String toLowerCase = stringUpperer.toLowerCase();
        System.out.println(toUpperCase);
        System.out.println(toLowerCase);
        System.out.println(strTest.toUpperCase());
        System.out.println(strTest.toLowerCase());

        String ipAddress = "192.168.100.1";
        // .的话需要用\\来转义，不然无法达到分割效果
        // 因为.代表的是任意字符，这样写就意味着以任意字符分割必然会出现问题的
        String []ip = ipAddress.split("\\.");
        for(String test : ip){
            System.out.println(test);
        }

        boolean strEquals = str.equals(stringUpperer);
        System.out.println(strEquals);

        // trim()去掉字符串两边的空格
        String sTrim = "   Hello World !!! Java  ";
        System.out.println(sTrim.trim().length());

        String sss =  "123456789";
        StringBuilder subString = new StringBuilder(sss);
        System.out.println(subString.substring(1,3));
        int times = Integer.parseInt(sss.substring(2, 3));
        System.out.println(times);


        // equalsIgnoreCase() 忽略比较大小写
        String h1 = "Hello World";
        String h2 = "hello world";
        boolean ignoreCase = h1.equalsIgnoreCase(h2);
        System.out.println(ignoreCase);

        System.out.println(h1.getBytes().length);

        String []strings = {"Tom","Jerry","HelloWorld"};
        System.out.println(String.join("123", strings));

        String format = String.format(h1, "2018-06-26");
        System.out.println(format);

        int compareTo = "HH".compareTo("hh");
        System.out.println(compareTo);

        int h = h1.indexOf("World");
        System.out.println(h);

        int o = h1.lastIndexOf("o");
        System.out.println(o);

        System.out.println(h2.concat(h1));

        System.out.println(ipAddress.replaceAll("\\.",":"));
        System.out.println(ipAddress.replaceFirst("\\.",":"));
    }

}
